/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.inscripcion.utils;

import java.util.ArrayList;

/**
 * @param title nombre del test
 * @param secction lista de secciones del test
 * @author linda perez 
 */
public class Test {
private String title;
private ArrayList sections=null;
    
    /**
     * @return the title
     */
    public Test(String title, ArrayList sec) {
        this.sections=sec;
        this.title=title;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
    

    /**
     * @return the sections
     */
    public ArrayList getSections() {
        return sections;
    }

    /**
     * @param sections the sections to set
     */
    public void setSections(ArrayList sections) {
        this.sections = sections;
        
    }
    
    /**
     * Se calcula la calificacion respecto sus secciones
     * porcentajes y la calificacion ingresada.
     * @return calificacion -1 si ocurrio un error
     */
    public int calculateRate(int rates[]) {
        int length=rates.length;
        int totalRate=0, rateSec;
        Section section;
        if(length==this.sections.size()){
        System.out.println("Error: El numero de notas introducidas debe ser "
                + "igual al numero de secciones del Test");
            System.exit(-1);
        }
        for(int i=0;i<length;i++){
            section = (Section)this.sections.get(i);
            rateSec=section.calculateScale(rates[i], section.getPercentage());
            totalRate=totalRate+rateSec;
            
                }
        return totalRate;
    }

}
